import java.util.LinkedList;
import java.util.List;

class Solution2 {
    private List<String> lists;
    public List<String> binaryTreePaths(TreeNode root) {
        lists = new LinkedList<String>();
        StringBuffer strBuff = new StringBuffer();
        dfs(root, strBuff);
        return lists;
    }
    private void dfs(TreeNode root, StringBuffer path) {
        if(root == null) return;
        if(!path.isEmpty()) path.append("->");
        path.append(root.val);
        if(root.left == null && root.right == null) {
            lists.add(path.toString());
            return;
        }
        dfs(root.left, path);
        dfs(root.right, path);
    }
}